﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Wu.MyBlog.Repository.Base
{
   public interface IBaseRepository<T> where T:class
    {
        #region 查询
        /// <summary>
        /// 单表查询
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        List<T> QueryWhere(Expression<Func<T, bool>> predicate);
        /// <summary>
        /// 多表关联查询
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="tableNames"></param>
        /// <returns></returns>
        List<T> QuertJion(Expression<Func<T, bool>> predicate, string[] tableNames);
        /// <summary>
        /// 升序查询还是降序查询
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="keySelector"></param>
        /// <param name="IsQueryOrderBy"></param>
        /// <returns></returns>
        List<T> QuertOrderBy<TKey>(Expression<Func<T, bool>> predicate, Expression<Func<T, TKey>>
            keySelector, bool IsQueryOrderBy);
        /// <summary>
        ///  升序分页查询还是降序分页
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="pageIndex"></param>
        /// <param name="pagesize"></param>
        /// <param name="rowcount"></param>
        /// <param name="predicate"></param>
        /// <param name="keySelector"></param>
        /// <param name="IsQueryOrderBy"></param>
        /// <returns></returns>
        List<T> QueryByPage<TKey>(int pageIndex, int pagesize, out int rowcount, Expression<Func<T, bool>> predicate, 
            Expression<Func<T, TKey>> keySelector, bool IsQueryOrderBy);

        #endregion

        #region 编辑
        /// <summary>
        /// 通过传入的model加需要修改的字段来更改数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="propertys"></param>
        void Edit(T model, string[] propertys);
        /// <summary>
        /// 直接查询之后再修改
        /// </summary>
        /// <param name="model"></param>
        void Edit(T model);
        #endregion

        #region 删除
        void Delete(T model, bool isadded);
        #endregion

        #region 增加
        void Add(T model);
        #endregion

        #region 统一提交
        int SaverChanges();

        #endregion

        #region 调用存储过程返回一个指定的TResult
        List<TResult> RunProc<TResult>(string sql, params object[] pamrs);
        #endregion
    }
}
 